<?php

/*
 *  This is NOT a freeware, use is subject to license terms
 *  @author: hzq <151680523@qq.com>

 * @version     $Id:filename.php
 */

class getKeyWord {

    public $apiUrl;
    public $ci = false;
    public $tags = false;

    function __construct($apiUrl) {
        $this->apiUrl = $apiUrl;
    }

    function fenci($str, $returnType="arr") {

        $tmp = str_replace('conetnts=', '', helper::Post($this->apiUrl, array("conetnts" => $str)));
        if ($returnType == 'arr') {
            $this->ci = explode(" ", $tmp);
        } else {
            $this->ci = $tmp;
        }
    }

    function getTags($dictPath) {
        $dict = include_once $dictPath;

        $arr = array();
        foreach ($this->ci as $v) {
            if ($dict[$v] > 0)
                array_push($arr, $v);
        }
        return $arr;
    }

    function initDict($path, $savePath) {

        $str = file_get_contents($path);
        $arr = explode("\n", $str);
        foreach ($arr as $k => $v) {

            $v = preg_replace('/\s+/', '', $v);
            if ($v

                )$arrs[$v] = strlen($v);
        }


        file_put_contents($savePath, '<?php return ' . var_export($arrs, true) . ' ;?>');
    }

}

?>
